var PconfigListObj= {
	showPconfigList:function(tableId, postUrl) {
		Tools.page({
			"tableId": tableId,
			"postUrl": postUrl,
			"bFilter": false,
			"iDisplayLength": 10,
			"aoColumns": [
			   {"mDataProp": "id"},
                           {"mDataProp": "confkey"},
                           {"mDataProp": "confvalue"},
                           {"mDataProp": "description"},
                           {"mDataProp": function (obj) {
                                   return "<button type=\"button\" data-id='"+obj.id+"' onclick='PconfigListObj.deletePconfigById("+obj.id+")'" +
							"class=\"btn btn-primary\" >删除</button>";
							}}
			],
			"aaSorting": [[2, "desc"]], //默认排序
			"aoColumnDefs": [//和aoColums类似，但他可以给指定列附近爱属性
			{"bSortable": true, "aTargets": [1]},  //这句话意思是第1,3,6,7,8,9列（从0开始算） 不能排序
			{"bSearchable": true, "aTargets": [1, 2]}, //bSearchable 这个属性表示是否可以全局搜索，其实在服务器端分页中是没用的
			]
		});
	},
	deletePconfigById:function(id){
			swal({
				title: "您确定要删除这条信息吗",
				text: "删除后将无法恢复，请谨慎操作！",
				type: "warning",
				showCancelButton: true,
				confirmButtonColor: "#DD6B55",
				confirmButtonText: "删除",
				closeOnConfirm: false
			}, function () {
				$.post("/pconfig/delete.do/"+id,{},function(result){
					if(result.success){
						swal({
							title: "删除成功！",
							text: "您已经永久删除了这条信息。",
							type: "success"
						},function(){
							window.location.href='/pconfig/pconfigList.show';
						});

					}else{
						swal("删除失败！", "删除了这条信息失败。", "error");
					}
				});
		});
	}
}

var PconfigUpdatedObj = function () {
	var validateFormData = function () {
		var icon = "<i class='fa fa-times-circle'></i> ";
		$("#pconfigForm").validate({
			rules: {
				confkey:{ required: true,maxlength: 255,},
				confvalue:{maxlength: 255,},
				description:{maxlength: 255,},
			},
			messages: {
				confkey:{ required: "配置key是必须项",maxlength:icon + "用户名必须255个字符以下",},
				confvalue:{maxlength:icon + "用户名必须255个字符以下",},
				description:{maxlength:icon + "用户名必须255个字符以下",},
			},
			success: function (label) {
				//console.log("111")
			},

			errorPlacement: function (error, element) {
				element.parent('div').append(error);
			},

			submitHandler: function (form) {
				updateDo();
			}
		});
	};
	var updateDo = function () {
		var data = utils.getFormData('pconfigForm');
		$("#updateBtn").attr({"disabled":"disabled"});
		utils.submitForm('pconfigForm', '/pconfig/update.do', data, function (result) {
			if (result.success) {
				swal({
					title: "更新成功！",
					text: "您的这条信息已录入系统。",
					type: "success"
				},function(){
					window.location.href ='/pconfig/pconfigList.show';
				});
			} else {
				swal("更新失败！", "更新这条信息失败。", "error");
				$("#updateBtn").removeAttr("disabled");
			}
		});
	};
	return {
		init: validateFormData,
		updateDo: updateDo
	}
}();

var laydate_ = function () {
	laydate({istime: true, format: 'YYYY-MM-DD  hh:mm:ss'})
};

function showEditDiv(id,obj){
	var $thisTDK = $(obj).parents("tr").find("td");
	$("#confkey").val($thisTDK[1].innerHTML);
	$("#confvalue").val($thisTDK[2].innerHTML);
	$("#description").val($thisTDK[3].innerHTML);
	$("#pconfig_id").val(id);
}